package main.java.com.lee.thread;


import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.concurrent.*;

/**
 * 多线demo01
 *
 * @author winston
 * @date 2021/12/01
 */
public class ThreadDemo01 {
	public static void main(String[] args) throws InterruptedException, ExecutionException {

		BigDecimal result = new BigDecimal(0.3560);
		DecimalFormat df = new DecimalFormat("0.00%");
		String r = df.format(result);
		System.out.println(r);

		NumberFormat format = NumberFormat.getPercentInstance();
//小数最大保留2位
		format.setMaximumFractionDigits(2);
		String str = format.format(result);
		System.out.println(str);
//		Thread thread = Thread.currentThread();
//		MyThread01 thread = new MyThread01();
//		Thread thread = new Thread(new MyRunnable01());

//		Thread thread = new Thread(() -> System.out.println(Thread.currentThread().getName()));

//		thread3();
//		thread4();
//		Thread thread = new Thread(new Runnable() {
//			@Override
//			public void run() {
//				System.out.println(Thread.currentThread().getName());
//			}
//		});
//		System.out.println("当前线程名称: " + thread.getName());
//		System.out.println("当前线程ID: " + thread.getId());
//		System.out.println("当前线程组名称: " + thread.getThreadGroup().getName());
//		System.out.println("当前线程状态: " + thread.getState());
//		System.out.println("当前线程优先级: " + thread.getPriority());
//		thread.start();
////		Thread.sleep(100);
//
//		System.out.println(thread.getState());
//		thread.isDaemon();
//		Thread t1 = new Thread();
//		t1.start();
//		fun1();

	}

	private static void fun1() {
		fun2();
	}

	private static void  fun2() {
		int i, j = 0;
		System.out.println();
	}

	private static void thread3() throws ExecutionException, InterruptedException {
		Callable<String> callable = new Callable<String>() {
			@Override
			public String call() throws Exception {
				return "hello thread";
			}
		};
		FutureTask<String> task = new FutureTask<>(callable);
		Thread thread = new Thread(task);
		thread.start();
		System.out.println(task.get());
	}

	private static void thread4() throws ExecutionException, InterruptedException {
		ExecutorService executorService = Executors.newFixedThreadPool(10);
		executorService.execute(() -> System.out.println("今天天气不错"));
		Future<String> submit = executorService.submit(new Runnable() {
			@Override
			public void run() {
				System.out.println("今天阳光明媚");
			}
		}, "hello");

		Future<?> submit1 = executorService.submit(new Runnable() {
			@Override
			public void run() {
				System.out.println("今天阳光明媚");
			}
		});


		System.out.println(submit.get());
		Future<String> future = executorService.submit(new Callable<String>() {

			@Override
			public String call() throws Exception {
				return "hello submit callable";
			}
		});
		System.out.println(future.get());

		Future<String> call = executorService.submit(new Callable<String>() {
			@Override
			public String call() throws Exception {
				return "hello world";
			}
		});
		System.out.println(call.get());
		executorService.shutdown();

	}


}
